package com.share.common.rabbit.MqSender;

import com.rabbitmq.client.MessageProperties;
import com.share.common.rabbit.MqConstant.MqConst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class Sender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 同步消息到消费者redis
     * @param uuid
     * @param message
     */
    public void sendRedis(String uuid,Object message) {
        // 创建correlationData
        CorrelationData correlationId = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(MqConst.EXCHANGE_REDIS_SYNC, MqConst.ROUTING_REDIS_SYNC, message,correlationId);
    }


    /**
     * 异步创建订单
     * @param uuid
     * @param message
     */
    public void sendCreateOrder(String uuid,Object message) {
        // 创建correlationData
        CorrelationData correlationId = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(MqConst.EXCHANGE_ORDER, MqConst.ROUTING_SUBMIT_ORDER, message,correlationId);
    }

    /**
     * 异步订单结束
     */
    public void sendOrderEnd(String uuid,Object message) {
        // 创建correlationData
        CorrelationData correlationId = new CorrelationData(uuid);
        rabbitTemplate.convertAndSend(MqConst.EXCHANGE_ORDER, MqConst.ROUTING_END_ORDER, message,correlationId);
    }


}
